<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta charset="UTF-8">
	<title>修改库存信息</title>
	<meta name="renderer" content="webkit">	
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">	
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">	
	<meta name="apple-mobile-web-app-status-bar-style" content="black">	
	<meta name="apple-mobile-web-app-capable" content="yes">	
	<meta name="format-detection" content="telephone=no">	
	<link rel="stylesheet" type="text/css" href="common/layui/css/layui.css" media="all">
	<link rel="stylesheet" type="text/css" href="common/bootstrap/css/bootstrap.css" media="all">
	<link rel="stylesheet" type="text/css" href="common/global.css" media="all">
	<link rel="stylesheet" type="text/css" href="css/personal.css" media="all">
	<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
</head>
<body class="childrenBody">
	<form class="layui-form" action="${pageContext.request.contextPath}/inventoryinfoAction!updateInventoryinfo" method="post" enctype="multipart/form-data">
		<!-- 汽车类型编号和配件类型 -->
		<input type="hidden" value="0" id="ctId">
		<input type="hidden" value="0" id="pjId">
		<input type="hidden" value="${param.itiid}" class="hidd" name="inventoryinfo.itiid">
		  <div class="layui-form-item">
			<div class="layui-inline">		
				<label class="layui-form-label">配件类型</label>
				<div class="layui-input-inline">
					<select class="pTITypeName" name="partstypeinfo.ptiid">
				    </select>
				</div>
			</div>
			<div class="layui-inline">		
				<label class="layui-form-label">使用汽车类型</label>
				<div class="layui-input-inline">
					<select class="cardtypeinfoName" name="cardtypeinfo.ctiid">
				    </select>
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">配件名称</label>
			<div class="layui-input-block">
				<input id="inpName" class="layui-input newsName iTIName" name="inventoryinfo.itiname" lay-verify="required" placeholder="请输入配件姓名" type="text">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">	
				<label class="layui-form-label">进价</label>
				<div class="layui-input-block">
					<input class="layui-input iTIPrice" lay-verify="number" name="inventoryinfo.itiprice" placeholder="请输入进价" type="text">
				</div>	
			</div>
			<div class="layui-inline">	
				<label class="layui-form-label">售价</label>
				<div class="layui-input-block">
					<input class="layui-input iTISelling" lay-verify="number" name="inventoryinfo.itiselling" placeholder="请输入售价" type="text">
				</div>	
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">图片</label>
				<div class="layui-input-block">
					<input type="text" class="hiddel1" name="inventoryinfo.itipicture"><input class="layui-icon iTIPicture" name="upload" type="file">
				</div>	
		</div>
		
		<div class="layui-form-item">
			<div class="layui-inline">	
				<label class="layui-form-label">型号参数</label>
				<div class="layui-input-block">
					<input class="layui-input iTIParameter" lay-verify="required" name="inventoryinfo.itiparameter" placeholder="请输入型号参数" type="text">
				</div>	
			</div>
			<div class="layui-inline">	
				<label class="layui-form-label">库存</label>
				<div class="layui-input-block">
					<input class="layui-input iTICount" lay-verify="number" placeholder="请输入库存" name="inventoryinfo.iticount" type="text">
				</div>	
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">作用</label>
			<div class="layui-input-block">
				<input class="layui-input iTIEffect" lay-verify="required" placeholder="请输入作用" name="inventoryinfo.itieffect" type="text">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<input type="submit" class="layui-btn updateInventoryinfo" lay-submit="" lay-filter="addNews" value="立即提交" />
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		    </div>
		</div>
	</form>
	<script type="text/javascript" src="common/layui/layui.js"></script>
	<script type="text/javascript" src="js/inventoryinfo.js"></script>
	
	<script type="text/javascript">
	//根据ID进行查询显示到修改页面
layui.use(['form','element','jquery','layer'], function(){
		var $=layui.jquery,form=layui.form;
		var id=$(".hidd").val();
		$.ajax({
			url:'../inventoryinfoAction!selectiTIId',
			async:false,
			dataType:'json',
			data:{"inventoryinfo.itiid":id},
			type:'post',
			success:function(msg){
					$(".iTIName").val(msg[0].itiname);
					$(".iTIPrice").val(msg[0].itiprice);
					$(".iTISelling").val(msg[0].itiselling);
					$(".hiddel1").val(msg[0].iTIPicture);
					$(".iTIParameter").val(msg[0].iTIParameter);
					$(".iTIEffect").val(msg[0].iTIEffect);
					$(".iTICount").val(msg[0].iTICount);
					$("#ctId").val(msg[0].pTIId);
					$("#pjId").val(msg[0].cTIId);
			}
		})
		partstypeinfo();
		cardtypeinfo();
		
	})
	
	function partstypeinfo(){
		//追加配件类型option
		var id=$("#ctId").val();
		$.ajax({
			type:"post",
			url:"../partstypeinfoAction!findAll",
			async:false,
			data:{"nowTime":new Date()},
			dataType:"json",
			success:function(msg){
				//追加
				$(msg).each(function(i){
					if(id==msg[i].ptiid){
						$(".pTITypeName").append("<option selected value="+msg[i].ptiid+">"+msg[i].ptitypeName+"</option>");
					}else{
						$(".pTITypeName").append("<option value="+msg[i].ptiid+">"+msg[i].ptitypeName+"</option>");
					}
				})
				var form = layui.form;
			    form.render();
			}
		});
	}
	function cardtypeinfo(){
		//追加汽车类型option
		var id=$("#pjId").val();
		$.ajax({
			type:"post",
			url:"../cardtypeinfoAction!findAll",
			async:false,
			data:{"nowTime":new Date()},
			dataType:"json",
			success:function(msg){
				//追加
				$(msg).each(function(i){
					if(id==msg[i].ctiid){
						$(".cardtypeinfoName").append("<option selected value="+msg[i].ctiid+">"+msg[i].ctitype+"</option>");
					}else{
						$(".cardtypeinfoName").append("<option value="+msg[i].ctiid+">"+msg[i].ctitype+"</option>");
					}
					
				})
				var form = layui.form;
			    form.render();
			}
		});
	}
	//修改
	/*
	$(document).on("click",".updateInventoryinfo",function(){
		var id=$(".hidd").val();
		var ctitype=$(".cardtypeinfoName option:checked").val();
		var pTITypeName=$(".pTITypeName option:checked").val();
		var iTIName=$(".iTIName").val();
		var iTIPrice=$(".iTIPrice").val();
		var iTISelling=$(".iTISelling").val();
		var iTIPicture=$(".iTIPicture").val();
		var iTIParameter=$(".iTIParameter").val();
		var iTIEffect=$(".iTIEffect").val();
		var iTICount=$(".iTICount").val();
		if(iTIName=="" || iTIPrice=="" || iTISelling=="" || iTIPicture=="" || iTIParameter=="" || iTIEffect=="" || iTICount==""){
			return;
		}
		$.ajax({
			url:'../inventoryinfoAction!updateInventoryinfo',
			async:false,
			dataType:'json',
			data:{"inventoryinfo.itiid":id,"partstypeinfo.ptiid":pTITypeName,"cardtypeinfo.ctiid":ctitype,"inventoryinfo.itiname":iTIName,"inventoryinfo.itiprice":iTIPrice,"inventoryinfo.itiselling":iTISelling,"inventoryinfo.itipicture":iTIPicture,"inventoryinfo.itiparameter":iTIParameter,"inventoryinfo.itieffect":iTIEffect,"inventoryinfo.iticount":iTICount},
			type:'post',
			success:function(msg){
				if(msg){
					alert("修改成功！");
					parent.location.reload();
				}else{
					alert("修改失败!");
				}
			}
		})
	})
	*/
	//验证
		$(document).on("click",".updateInventoryinfo",function(){
			var id=$(".hidd").val();
			var iTIName=$(".iTIName").val();
			var iTIPrice=$(".iTIPrice").val();
			var iTISelling=$(".iTISelling").val();
			var iTIPicture=$(".iTIPicture").val();
			var iTIParameter=$(".iTIParameter").val();
			var iTIEffect=$(".iTIEffect").val();
			var iTICount=$(".iTICount").val();
			if(iTIName=="" || iTIPrice=="" || iTISelling=="" || iTIPicture=="" || iTIParameter=="" || iTIEffect=="" || iTICount==""){
				return;
			}
			  layer.alert(data.msg, {offset: 't',icon: 6},function () {
	                layer.close(layer.index);
	                window.parent.location.reload();
	            });
	})
	</script>
</body>
</html>